package logic

import (
	"context"
	"person/personrpc/personrpc"

	"person/personapi/internal/svc"
	"person/personapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PersonAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPersonAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PersonAddLogic {
	return &PersonAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PersonAddLogic) PersonAdd(req *types.PersonAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.PersonRpc.UserAdd(l.ctx, &personrpc.UserAddRequest{
		Userid: int64(req.UserId),
		Name:   req.Name,
		Price:  int64(req.Price),
		Class:  req.Class,
	})
	if err != nil {
		return &types.Response{
			Message: "添加失败",
			Code:    "500",
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Code:    "200",
		Data:    add,
	}, nil
}
